﻿/// <reference path="jquery-1.11.2.min.js" />

function isExistOption(id, value) {
    var isExist = false;
    var count = $('#' + id).find('option').length;
    for (var i = 0; i < count; i++) {
        if ($('#' + id).get(0).options[i].value == value) {
            isExist = true;
            break;
        }
    }
    return isExist;
}

function padLeft(num, length) {
    return (Array(length).join('0') + num).slice(-length);
}

function CheckUser() {
    //$.cookie('openid', '');
    if ($.cookie('openid') == null || $.cookie('openid') == '') {
        $.cookie('url', '');
        window.parent.location.href = 'default.html';
    }
    else {
        $.ajax({
            type: "get",
            url: "api/common.ashx?ac=checkuser&k=" + Math.random(),
            error: function () {
                //alert("用户验证失败");
                window.parent.location.href = 'index.html';
            },
            success: function (data) {
                if (data == 'False') {
                    window.parent.location.href = 'login.html';
                }
                else if (data == 'No') {
                    window.parent.location.href = 'default.html';
                }
            }
        });
    }
}
function showToast(content) {
    if ($('#toast') != null) {
        $('#toast_content').html(content);
        $('#toast').show();
        setTimeout(function () {
            $('#toast').hide();
        }, 1000);
    }
}
function toDecimal2(x) {
    var f = parseFloat(x);
    if (isNaN(f)) {
        return false;
    }
    var f = Math.round(x * 100) / 100;
    var s = f.toString();
    var rs = s.indexOf('.');
    if (rs < 0) {
        rs = s.length;
        s += '.';
    }
    while (s.length <= rs + 2) {
        s += '0';
    }
    return s;
}

